<template>
	<view class="ys">
		<view class="navlist">
			<view :class="isActive == item.type ?'nav_item active':'nav_item'" v-for="(item,index) in navlist"
				:key="index" @click="changeNav(item)">
				{{item.text}}
			</view>
		</view>
		<view class="list" v-if="list.length != 0">
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="top">
					<image src="/static/index/head.png" mode=""></image>
					<view class="info">
						<view class="name">
							账号: {{item.username}}
						</view>
						<view class="phone">
							姓名: {{item.name}}
						</view>
						<view class="phone">
							手机号: {{item.phone}}
						</view>
					</view>
					<view class="btns" v-if="item.status == 0">
						<button @click="DownTiSure(item,index)" :disabled="loading">通过</button>
						<button @click="DownTiBack(item,index)" :disabled="loading">驳回</button>
					</view>
				</view>
				<view class="bot" :id="'bot'+index">
					<view class="title">
						<text :class="i == item.botID ?'on':''" v-for="(sitem,i) in item.botlist" :key="i"
							@click="changeBot(item,i)">{{sitem}}</text>
					</view>
					<swiper :current="item.botID" @change="changeItem(item,$event,index)"
						:style="{height:item.height+'px'}">
						<swiper-item>
							<view class="swiper-item">
								<view class="li">
									提现方式：<text>{{item.to_type_name}}</text>
								</view>
								<view class="li">
									提现状态：<text>{{item.status_name}}</text>
								</view>
								<view class="li">
									提现金额：<text>￥{{item.num}}</text>
								</view>
								<view class="li">
									提现手续费：<text>￥{{item.fees}}</text>
								</view>
								<view class="li">
									实际金额：<text>￥{{item.real_num}}</text>
								</view>
								<view class="li">
									操作时间：<text>{{item.add_time}}</text>
								</view>
							</view>
						</swiper-item>
						<swiper-item>
							<view class="swiper-item">
								<view class="li">
									银行名称: <text>{{item.bank_name}}</text>
								</view>
								<view class="li">
									银行户名: <text>{{item.bank_user}}</text>
								</view>
								<view class="li">
									开户支行: <text>{{item.bank_open}}</text>
								</view>
								<view class="li">
									银行卡号: <text>{{item.bank_num}}</text>
								</view>
							</view>
						</swiper-item>
						<swiper-item>
							<view class="swiper-item">
								<image :src="item.ali_code | getImg" mode="widthFix"></image>
							</view>
						</swiper-item>
						<swiper-item>
							<view class="swiper-item swiper-item3">
								<image :src="item.wechat_code | getImg" mode="widthFix"></image>
							</view>
						</swiper-item>
					</swiper>
				</view>
			</view>
		</view>
		<view class="no-list" v-else>
			- 暂无数据 -
		</view>
	</view>
</template>

<script>
	import {
		DownTi,
		DownTiSure,
		DownTiBack
	} from "@/api/user.js"
	export default {
		data() {
			return {
				list: [],
				page: 1,
				last_page: 1,
				height: '',
				loading: false,
				navlist: [{
						text: '全部',
						type: '5'
					},
					{
						text: '待审核',
						type: '0'
					},
					{
						text: '通过',
						type: '1'
					},
					{
						text: '驳回',
						type: '2'
					}
				],
				isActive: 5,
				info: {
					botlist: ['提现信息', '银行卡', '支付宝', '微信'],
					botID: 0,
					height: ''
				}
			}
		},
		onLoad(e) {
			if (e.id) this.id = e.id
			this.DownTi()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.DownTi()
			}
		},
		methods: {
			DownTiSure(item, index) {
				var that = this
				that.loading = true
				uni.showModal({
					title: '提示',
					content: '是否通过?',
					success(res) {
						if (res.confirm) {
							DownTiSure({
								id: item.id
							}).then(res => {
								that.loading = false
								uni.$showMsg(res.message)
								that.$set(that.list[index], 'status', 1)
								that.$set(that.list[index], 'status_name', '已通过')
							})
						} else {
							that.loading = false
						}
					}
				})
			},
			DownTiBack(item, index) {
				var that = this
				that.loading = true
				uni.showModal({
					title: '提示',
					content: '是否驳回?',
					success(res) {
						if (res.confirm) {
							DownTiBack({
								id: item.id
							}).then(res => {
								that.loading = false
								uni.$showMsg(res.message)
								that.$set(that.list[index], 'status', 2)
								that.$set(that.list[index], 'status_name', '已驳回')
							})
						} else {
							that.loading = false
						}
					}
				})
			},
			changeNav(i) {
				this.isActive = i.type
				this.page = 1
				this.last_page = 1
				this.list = []
				this.DownTi()
			},
			changeItem(item, e, i) {
				item.botID = e.detail.current
				var that = this
				setTimeout(() => {
					let info = uni.createSelectorQuery().selectAll(`#bot${i} .swiper-item`)
					info.boundingClientRect(function(data) { //data - 各种参数
						item.height = data[item.botID].height
					}).exec()
				})
			},
			changeBot(item, i) {
				item.botID = i
			},
			DownTi() {
				DownTi({
					page: this.page,
					status: this.isActive
				}).then(res => {
					if (res.status == 1) {
						this.list = this.list.concat(res.data.data)
						this.list = this.list.map(item => {
							return item = {
								...item,
								...this.info
							}
						})
						console.log(this.list);
						this.last_page = res.data.last_page
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #f2f2f2;
	}

	.navlist {
		display: flex;
		justify-content: space-between;
		position: sticky;
		top: 0;
		/* #ifdef H5 */
		top: 44px;
		/* #endif */
		width: 100%;
		max-width: 500px;
		z-index: 999;
		background: #6b7490;

		.nav_item {
			width: 25%;
			text-align: center;
			color: #ffffff80;
			height: 40px;
			justify-content: center;
			// line-height: 50px;
			font-weight: bold;
			display: flex;
			flex-direction: column;
			font-size: 14px;
		}

		.active {
			color: #fff;
			position: relative;
		}

		.active::after {
			position: absolute;
			content: '';
			width: 25px;
			height: 3px;
			background: #fff;
			left: 50%;
			bottom: 4px;
			transform: translate(-50%);
		}
	}

	.list {
		padding: 10px;

		.item {
			padding: 10px;
			border-radius: 5px;
			box-sizing: border-box;
			background: #fff;
			margin-bottom: 10px;

			.top {
				display: flex;
				align-items: center;
			}

			.bot {
				font-size: 14px;
				border-top: 1px solid #eee;
				padding-top: 10px;
				margin-top: 10px;

				.title {
					width: 100%;
					margin-bottom: 10px;

					text {
						margin-right: 8px;
						font-size: 12px;
						color: #777;

						&.on {
							color: #000;
							font-size: 14px;
							font-weight: bold;
						}
					}
				}

				.li {
					padding: 5px 0;
					font-size: 12px;
					color: #777;
					display: flex;
					justify-content: space-between;

					text {
						color: #000;
						font-size: 12px;
					}

				}
			}

			image {
				width: 50px;
				height: 50px;
				margin-right: 10px;
			}

			.swiper-item {
				box-sizing: border-box;

				image {
					width: 90%;
					margin-left: 5%;
				}
			}

			.info {
				flex: 1;
				padding: 0 15px;
				box-sizing: border-box;

				.name {
					font-size: 14px;
					margin-bottom: 3px;
					font-weight: bold;
				}

				.phone {
					font-size: 12px;
					color: #777;
					margin-bottom: 3px;

					text {
						color: #ff6b27;
						font-weight: bold;
					}
				}
			}

			.btns {
				button {
					width: 70px;
					height: 30px;
					margin-bottom: 10px;
					line-height: 30px;
					font-size: 13px;
					background: #E1ECFE;
					color: #6b7490;
					font-weight: bold;
				}
			}

		}
	}
</style>